/**
 *******************************************************************************
 * @file user_config.h
 * @author .ISS_AUTO (hudandan@issauto.com)
 * @version 0.1
 * @date 2024.07.15
 *                  1. 新增N32G45XCE的内存空间分配管理；
 *       2024-07-26
 *                  1. 修改Execute Flag的存储位置;
 *       2024-08-15
 *                  1. 修改APP1&APP2的存储位置;
 *       2024-11-19
 *                  1. 修改APP1&APP2的存储位置(Bootloader方案下)为固定地址;
 *
 * @brief MCU: Nations Technologies. e.g. N32G455.
 *
 * @copyright Copyright (c) 2024 ISSAUTO TECH Co., Ltd. All rights reserved.
 *
 *******************************************************************************
 */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USER_CONFIG_H_
#define __USER_CONFIG_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#if defined(N32A455)
#include "n32a455.h"
#endif

#if defined(N32G45X)
#include "n32g45x.h"
#endif

#if !defined(N32A455) && !defined(N32G45X)
//!< ONLY FOR DEBUG
#include "n32g45x.h"
#endif

/* Exported constants --------------------------------------------------------*/

/** @addtogroup Defines user app/boot configure
 * @{
 *     #define N32G45XCC //!< 256K Flash
 *     #define N32G45XCE //!< 512K Flash
 */

/** @note NO BOOT DEFAULT CONFIGURATION
 * ----------------------------------------
 * ROM（Flash 内存地址分区规划，Size: 256K）
 * ----------------------------------------
 *       起始地址      结束地址     总大小/KB
 * ----------------------------------------
 * App   0x08008800   0x08031FFF     200
 * Flag  0x08032000   0x080327FF     2
 * User  0x08032800   …              …
 * …     …            0x0803FFFF     …
 * ----------------------------------------
 */
#define FLASH_START_ADDR             (0x08000000U)
#define FLASH_MAX_SIZE               (0x00040000U)  //!< N32G45X Flash大小 256K * 1024
#define FLASH_PAGE_SIZE              (0x00000800U)  //!< 2KBytes

#define FLASH_MAX_SIZE_APP           (0x00032000U)  //!< APP reserves 200K space
#define FLASH_MAX_SIZE_BOOT          FLASH_MAX_SIZE_APP  //!< NO BOOTLOAD space
#define FLASH_MAX_SIZE_EXE_FLAG      (FLASH_PAGE_SIZE)  //!< Flag reserves 2K space
#define FLASH_MAX_SIZE_USER          (FLASH_PAGE_SIZE * 16)  //!< USER reserves 2K*16 space

/*!< FLASH Partition Address */
#define FLASH_END_ADDR               (FLASH_START_ADDR + FLASH_MAX_SIZE - 1)

/*!< 📌BOOTLOAD */
#define FLASH_ADDR_BOOT_START        (FLASH_START_ADDR)
#define FLASH_ADDR_BOOT_END          (FLASH_ADDR_BOOT_START + FLASH_MAX_SIZE_BOOT - 1)

/*!< 📌ROM execute flag */
#define FLASH_ADDR_EXE_FLAG_START    (FLASH_ADDR_BOOT_END + 1)
#define FLASH_ADDR_EXE_FLAG_END      (FLASH_ADDR_EXE_FLAG_START + FLASH_MAX_SIZE_EXE_FLAG - 1)

/*!< User */
#define FLASH_ADDR_USER_START        (FLASH_ADDR_EXE_FLAG_END + 1)
#define FLASH_ADDR_USER_END          (FLASH_ADDR_USER_START + FLASH_MAX_SIZE_USER - 1)

/*!< 📌APP program */
#define FLASH_ADDR_APP_START         (FLASH_END_ADDR - FLASH_PAGE_SIZE - 2 * FLASH_MAX_SIZE_APP + 1)
#define FLASH_ADDR_APP_END           (FLASH_END_ADDR - FLASH_PAGE_SIZE - FLASH_MAX_SIZE_APP)

/*!< 📌APP-BK program */
#define FLASH_ADDR_APP_TEMP_START    (FLASH_END_ADDR - FLASH_PAGE_SIZE - FLASH_MAX_SIZE_APP + 1)
#define FLASH_ADDR_APP_TEMP_END      (FLASH_END_ADDR - FLASH_PAGE_SIZE)

/*!< Flag Code */
#define ROM_EXE_BOOT_ID              ((uint32_t)0x12345678U)  /*!< ROM execute Bootloader flag */
#define ROM_EXE_APP_UPDATE_ID        ((uint32_t)0x87654321U)  /*!< ROM execute App Update flag */
#define ROM_EXE_APP_ID               ((uint32_t)0xEB90EB90U)  /*!< ROM execute App flag */


/**
  * @}
  */


/** @addtogroup Middleware Driver Layer Module Configuration(Only For Debug)
  * @{
  */

/**
  * @}
  */


/* Exported macro ------------------------------------------------------------*/



#ifdef __cplusplus
}
#endif

#endif /* __USER_CONFIG_H_ */

/* END OF FILE ---------------------------------------------------------------*/
